<template>
  <div class="page">
    <navigation>{{ $t('收款方式') }}</navigation>
    <div class="padded-bottom">
      <div v-if="list.length>0" class="otc-list">
        <nuxt-link v-for="item in list" :key="item.id" :to="routerLink[item.proceeds_type] + '?type=edit&id=' + item.id" class="otc-item">
          <img :src="item.icon" alt="" class="icon">
          <div class="title">{{ $t(item.name) }}({{ item.account }})</div>
          <i class="iconfont icon-jiantouarrow487"></i>
        </nuxt-link>
      </div>
      <div v-else class="no-date">
        <i class="iconfont icon-qianbao"></i>
        <p>{{ $t('您还没有收款信息，快去创建吧！') }}</p>
      </div>
      <button type="button" class="menubtn" @click="showSheet=true">{{ $t('创建收款信息') }}</button>
      <div class="action-sheet" :class="{'open': showSheet}">
        <div class="action-sheet-mask" @click="showSheet=false"></div>
        <div class="action-sheet-list">
          <nuxt-link v-for="(item, index) in method" :key="index" :to="routerLink[item.proceeds_type]+'?type=add'" class="action-sheet-item">{{ $t(item.name) }}</nuxt-link>
          <div class="action-sheet-hr"></div>
          <button type="button" class="action-sheet-item cancel" @click="showSheet=false">{{ $t('取消') }}</button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapActions } from 'vuex'
import storage from '@/utils/storage'
import navigation from '@/components/Navigation'
export default {
  components: { navigation },
  data () {
    return {
      showSheet: false,
      list: [],
      method: [],
      routerLink: {
        wxpay: 'pay-wechat',
        alipay: 'pay-alipay',
        bank: 'pay-bank'
      }
    }
  },
  beforeMount () {
    this.getGathering()
      .then((data) => {
        this.list = data.data
      })
    this.getMethod()
      .then((data) => {
        this.method = data.data
      })
  },
  methods: {
    ...mapActions({
      getGathering: 'user/getGathering',
      getMethod: 'user/getMethod'
    }),
    gotoEdit (index) {
      const data = this.list[index]
      storage.set('cardData', JSON.stringify(data))
      this.$router.push({
        path: this.routerLink[data.proceeds_type],
        query: {
          type: 'edit'
        }
      })
    }
  }
}
</script>
<style scoped>
.padded-bottom {
  padding-bottom: 40px;
}
.no-date {
  height: 40vh;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  text-align: center;
  font-size: 14px;
  color: #666666;
}
.no-date .iconfont {
  font-size: 80px;
  margin-bottom: 20px;
  color: #666;
}
.otc-list {
  overflow: hidden;
  }
.otc-item {
  position: relative;
  padding: 0 15px;
  line-height: 50px;
  height: 50px;
  font-size: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.otc-item:after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 15px;
  right: 0;
  height: 0;
  border-bottom: 1px solid #eee;
}
.otc-item .icon {
  position: static;
  flex-shrink: 0;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  margin-right: 15px;
}
.otc-item .title {
  flex-grow: 1;
}
.menubtn {
  position: fixed;
  bottom: 0;
  left: 0;
  line-height: 40px;
  height: 40px;
  width: 100%;
  background: #1b8afe;
  text-align: center;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
}
.action-sheet.open .action-sheet-mask {
  display: block;
}
.action-sheet.open .action-sheet-list {
  transform: translateY(0);
  transition: 0.3s;
}
.action-sheet-mask {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.64);
}
.action-sheet-list {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background-color: #eee;
  transform: translateY(100%);
}
.action-sheet-item {
  display: block;width: 100%;
  line-height: 40px;
  height: 40px;
  text-align: center;
  background-color: #fff;
  cursor: pointer;
}
.action-sheet-item + .action-sheet-item {
  border-top: 1px solid #eee;
}
.action-sheet-item:active {
  background-color: #f2f3f5;
}
.action-sheet-hr {
  height: 10px;
}
</style>
